package com.scw.hothot;

import android.annotation.SuppressLint;

import com.elvishew.xlog.LogLevel;
import com.elvishew.xlog.printer.file.naming.FileNameGenerator;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class myFileNameGenerator implements FileNameGenerator {

    String fileName = "";

    public myFileNameGenerator(String args) {
        this.fileName = args;
    }

    ThreadLocal<SimpleDateFormat> mLocalDateFormat = new ThreadLocal<SimpleDateFormat>() {

        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss", Locale.US);
        }
    };

    @Override
    public boolean isFileNameChangeable() {
        return true;
    }

    /**
     * Generate a file name which represent a specific date.
     */
    @Override
    public String generateFileName(int logLevel, long timestamp) {
        SimpleDateFormat sdf = mLocalDateFormat.get();
        sdf.setTimeZone(TimeZone.getDefault());
        //return sdf.format(new Date(timestamp));
        if(fileName.isEmpty()){
            return sdf.format(new Date(timestamp));
        }else {
            return fileName;
        }
    }
}
